package servlet;

import db.DB;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/addslist")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class addslist extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type", "text/html;charset=utf-8");
        int customerid = Integer.parseInt(req.getParameter("customerid"));
        int state = Integer.parseInt(req.getParameter("state"));
        String remark =req.getParameter("remark");
        HttpSession session=req.getSession();
        User user=(User)session.getAttribute("user");
        String message = null; //定义message变量
        if (new DB().addslist(customerid,state,remark,user.getId())) {
            session.setAttribute("salepage","createlist2");
            resp.sendRedirect("salesystem.jsp");
            return; }
        else {
            System.out.println("failed");
            message = "创建失败！";
            session.setAttribute("message",message);
            return;
        }
    }
}

